package com.atguigu.controller;



import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController {

 @DubboReference
private DictService dictService;



    //跳转dict首页
    @RequestMapping
    public String index(){
        return "dict/index";
    }

    //树形页面
    @RequestMapping("/findZnodes")
    //RequestParam:接收默认值
    @ResponseBody //给前端返回json数据
    public Result findZNodes(@RequestParam(value = "id",defaultValue = "0") Long id){
        System.out.println("id = " + id);
        //调用业务层,根据id查询子级
        List<Map<String, Object>> zNodes = dictService.findZNodes(id);
        return Result.ok(zNodes);
    }

    @RequestMapping("/findListByParentId/{areaId}")
    @ResponseBody //接受前端的json数据
    public Result findListByParentId(@PathVariable Long areaId){
        List<Dict> dictList = dictService.findDictByParentId(areaId);
        return Result.ok(dictList);
    }
}